package com.dhj.top100;

public class MaxArea {

    public static void main(String[] args) {
        System.out.println(maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
    }

    public static int maxArea(int[] height) {
        int maxArea = 0, left = 1, right = height.length;
        while (right > left){
            maxArea = Math.max((right -left)*Math.min(height[left-1], height[right-1]), maxArea);
            if(height[left-1] > height[right-1]){
                right --;
            }else{
                left++;
            }
        }
        return maxArea;
    }

}
